﻿
/**
 * Module dependencies.
 */

var express = require( 'express' );
var routes = require( './routes' );
var index = require('./routes/index');
var user = require( './routes/user' );
var vacation = require( './routes/vacation' );
var http = require( 'http' );
//var connect = require("connect");
var path = require( 'path' );
var winston = require( 'winston' );
var fs = require( 'fs' );

//var logFile = fs.createWriteStream('./logger.log', {flags:'a'});

var myLogger = new ( winston.Logger )( {
    transports: [
        new ( winston.transports.Console )(),
        new ( winston.transports.File )( { filename: './exception.log' })
    ],
    exitOnError: false
});

process.on( "uncaughtException", function ( exception ) {
    console.log( 'catch exception========' + exception );
    myLogger.log( 'error', exception.message );
});


var app = express();

// all environments
app.set( 'port', process.env.PORT || 3000 );
app.set( 'views', path.join( __dirname, 'views' ) );
app.set( 'view engine', 'jade' );
app.use( express.favicon() );
app.use( express.logger( 'dev' ) );
app.use( express.json() );
app.use( express.urlencoded() );
app.use( express.methodOverride() );
app.use( express.cookieParser() );
app.use( express.session( { secret: "ws-eka" }) );
app.use( app.router );
app.use( require( 'stylus' ).middleware( path.join( __dirname, 'public' ) ) );
app.use( express.static( path.join( __dirname, 'public' ) ) );
//app.use(connect.logger({ //添加日志
//		  	stream:logFile,
//		  	format:':req[Host]:url - :date --> :status === :req[Session]',
//		  	immediate:true
//		  }));

// development only
if ( 'development' == app.get( 'env' ) ) {
    app.use( express.errorHandler() );
}

//route config
app.get( '/', user.login );
app.post( '/', user.authen );
app.get( '/Home/Index', routes.index );
app.get( '/Reject/Comment', index.comment );
app.get( '/Vacation/List', vacation.index );
app.get( '/Vacation/Detail', vacation.detail );
app.post( '/Vacation/Detail', vacation.operate );
app.get( '/Vacation/MyWork', vacation.mywork );


http.createServer( app ).listen( app.get( 'port' ), function () {
    console.log( 'Express server listening on port ' + app.get( 'port' ) );
});
